var MongoClient = require("mongodb").MongoClient;
var url = "mongodb://localhost:27017/";

MongoClient.connect(url, {useNewUrlParser: true, useUnifiedTopology: true}, function(err, db) {
  if(err) throw err
  var dbo = db.db("laochen")
  // 查询条件
  var whereStr = {"userName": "老陈"}
  var updateStr = {$set: {"type": "小胖帅"}}
  dbo.collection("users").updateOne(whereStr, updateStr, function(err, res) {
    if (err) throw err
    console.log("文档更新成功")
    db.close()
  })

})